package com.goldmantis.alitrip.controller;

import com.goldmantis.alitrip.service.ApprovalGetService;
import com.goldmantis.alitrip.service.ApprovalUpdateService;
import com.taobao.api.request.AlitripBtripApprovalUpdateRequest;
import com.taobao.api.response.AlitripBtripApplyGetResponse;
import com.taobao.api.response.AlitripBtripApprovalUpdateResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @Author:Shmily
 * @Description:
 * @Date:Create in 17:55 2018/1/15
 */
@Controller
@CrossOrigin(value = "*",maxAge = 3600)
@RequestMapping("approval/get/")
public class ApprovalGetController {

    private static final Logger logger = LoggerFactory.getLogger(ApprovalGetController.class);

    @Autowired
    private ApprovalGetService approvalGetService;

    /**
     * 查找审批单
     * @param applyId 阿里商旅审批单Id
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "{applyId}",method = RequestMethod.GET)
    public ResponseEntity<AlitripBtripApplyGetResponse> getApproval(@PathVariable Long applyId) throws Exception {
        try {

            AlitripBtripApplyGetResponse rsp = approvalGetService.getApproval(applyId);

            return ResponseEntity.ok(rsp);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(applyId+ "单据获取失败");
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }


}
